var url = require("url");
var page_obj = require("page_obj");
require("modules_ws");
require("modules_ui");

function route(req, res) {
    var isFound = 0;
    var path_name = url.parse(req.url).pathname.toLowerCase();
    var page_instant = new page_obj.page_obj();
    var pages = page_instant.getPageList();
//    console.log(req);
//    console.log(res);

    if((pages[path_name]) && (typeof pages[path_name].page_handler === 'function')) {
        pages[path_name].page_handler(req, res);
        isFound = 1;
    }

    if(!isFound) {
        console.log(pages);
        res.writeHead(400, {"Content-Type": "text/html"});
        res.write(pages.toString() + "Page not found");
    }
}

exports.route = route;
